var path = require('path');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var ROOT_PATH = path.resolve(__dirname);
var STATIC = path.resolve(__dirname,'dist');
var TEM_PATH = path.resolve(ROOT_PATH);

var isProduction = function () {
    return false;
};

module.exports = {
    devtool: 'cheap-module-eval-source-map',
    entry: [
//        'webpack-hot-middleware/client',
        './assets/js/main',
      ],
    output: {
        path: path.join(__dirname,'dist'),
//        filename: 'bundle.js', //单页应用不需要多文件直接指定名称
        filename: './assets/js/[name].js', 
    },
    resolve: {
        //定义根目录，require之类的引用路径
        root: ROOT_PATH,
        extensions: ['', '.js', '.jsx']
    },
    devtool: isProduction() ? false : 'eval-source-map',
    devServer: {
        historyApiFallback: true,
        hot: true,
        inline: true,
        progress: true,
        historyApiFallback: {
            index: '/'
        },
        //只要配置dev server map这个参数就可以了
        proxy: {
            '/api/*': {
                target: '192.168.1.101:8080',
                secure: false
            }
        }
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loaders: ['babel'],
                exclude: /node_modules/,
                include: __dirname
            },
             {
                test: /\.css|less$/,
                loaders: ['style', 'css', 'less']
            },
//            { test: /\.(png|jpg)$/, loader: 'url-loader?limit=81920'}
            {
                test: /\.(png|jpg|gif)$/,
                loader: 'file-loader?name=assets/images/[name].[ext]'
            }
        ]
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            minimize: isProduction()?true:false,
            compress:{
                drop_console:isProduction()?true:false
            }
        }),
//        new ExtractTextPlugin("styles.css"),
        new HtmlwebpackPlugin({
            title: 'run demo',
            template: 'html-withimg-loader!' + path.resolve(TEM_PATH, 'index.html'),
            filename: 'index.html',
//            chunks: ['bundle', 'vendors'],
            inject: 'body'
        }),
        //把入口文件里面的数组打包成verdors.js
//        new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js')
    ]
}